import { http } from "@/utils/http";

/**
 * 查询参数（分页 + 条件）
 */
export interface DangerSourceListCommand extends BasePageQuery {
  dangerSourceName?: string;
  dangerType?: string;
  actionMakerName?: string;
  sourceType?: string;
}

/**
 * 响应数据结构
 */
/**
 * 响应数据结构
 */
export interface DangerSourcePageResponse {
  dangerSourceId: number;
  dangerSourceCode: string;
  dangerType: string;
  dangerSourceName: string;
  dutyDeptId?: number;
  sendDeptId?: number;
  actionDeptId?: number;
  professionalCategory?: string;
  findTime?: string;
  dangerSourceOrigin?: string;
  dangerSourceMajorFlag?: string;
  controlState?: string;
  dangerSourceDescribe?: string;
  harmDescribe?: string;
  emergeCause?: string;
  rootCause?: string;
  triggerFactor?: string;
  typicalEvent?: string;
  consequence?: string;
  havePreventMeasures?: string;
  verification?: string;
  remark?: string;
  riskBeforePossibility?: number;
  riskBeforeSeriousness?: number;
  riskBeforeVal?: string;
  riskBeforeRank?: string;
  riskAfterPossibility?: number;
  riskAfterSeriousness?: number;
  riskAfterVal?: string;
  riskAfterRank?: string;
  monitorDeptPeople?: string;
  monitorTrackSituation?: string;
  monitorFrequencyDate?: string;
  controlAfterPossibility?: number;
  controlAfterSeriousness?: number;
  controlAfterVal?: string;
  controlAfterRank?: string;
  derivedRiskExistFlag?: string;
  derivedRiskDescribe?: string;
  createBy?: string;
  createTime: string;
  updateBy?: string;
  updateTime?: string;
  status?: string;
  relatedReformId?: number;
  relatedReformCode?: string;
  correctiveAction?: string;
  correctiveDeadline?: string;
  precautionAction?: string;
  precautionDeadline?: string;
  actionMakerName?: string;
  actionMakeTime?: string;
  riskCode?: string;
  riskId?: number;
  relatedQuestionId?: number;
  associatedFlag?: string;
  deriveDangerSourceId?: number;
  leaderContent?: string;
  leaderIsOk?: string;
  leaderName?: string;
  leaderTime?: string;
  deleted?: boolean;
  creatorId?: number;
  updaterId?: number;

  /** 新增字段：来源类型（1=危险源，2=隐患） */
  sourceType?: string;

  /** 新增字段：隐患迁移专属 */
  drillPlanId?: number;
  hiddenTroubleRank?: string;
  rankJudgeName?: string;
  rankJudgeTime?: string;
  hiddenTroubleType?: string;
  superviseDeptId?: number;
  rectificationTime?: string;
  rectificationSchedule?: number;
  finishTime?: string;
  relatedRiskAction?: string;
  tempControlAction?: string;
  reformFunds?: string;
  actionIsOk?: string;
  actionEval?: string;
  actionEvalerName?: string;
  actionEvalTime?: string;

  dutyDeptName?: string;
  actionDeptName?: string;
  reportTittle?: string;
  reformTittle?: string;
}


/**
 * 获取危险源分页列表
 */
export function getDangerSourceListApi(params: DangerSourceListCommand) {
  return http.request<ResponseData<PageDTO<DangerSourcePageResponse>>>(
    "get",
    "/airport/danger-source/list",
    {
      params
    }
  );
}

/**
 * 导出危险源 Excel
 */
export const exportDangerSourceExcelApi = (
  params: DangerSourceListCommand,
  fileName: string
) => {
  return http.download("/airport/danger-source/excel", fileName, {
    params
  });
};

/**
 * 删除危险源
 */
export const deleteDangerSourceApi = (data: Array<number>) => {
  return http.request<ResponseData<void>>("delete", "/airport/danger-source", {
    params: {
      ids: data.toString()
    }
  });
};

/**
 * 新增命令结构
 */
export interface AddDangerSourceCommand {
  dangerSourceId: number;
  dangerSourceCode: string;
  dangerSourceName: string;
  dangerType?: string;
  dangerSourceDescribe?: string;
  harmDescribe?: string;
  emergeCause?: string;
  rootCause?: string;
  relatedReformId?: number;
  relatedReformCode?: string;
  correctiveAction?: string;
  correctiveDeadline?: string;
  precautionAction?: string;
  precautionDeadline?: string;
  actionMakerName?: string;
  actionMakeTime?: string;
  riskCode?: string;
  createTime: string;
}

/**
 * 新增危险源
 */
export const addDangerSourceApi = (data: AddDangerSourceCommand) => {
  return http.request<ResponseData<void>>("post", "/airport/danger-source", {
    data
  });
};

/**
 * 更新命令结构
 */
export interface UpdateDangerSourceCommand extends AddDangerSourceCommand {
  dangerSourceId: number;
  dangerSourceCode: string;
  dangerSourceName: string;
  dangerType?: string;
  dangerSourceDescribe?: string;
  harmDescribe?: string;
  emergeCause?: string;
  rootCause?: string;
  relatedReformId?: number;
  relatedReformCode?: string;
  correctiveAction?: string;
  correctiveDeadline?: string;
  precautionAction?: string;
  precautionDeadline?: string;
  actionMakerName?: string;
  actionMakeTime?: string;
  riskCode?: string;
  createTime: string;
}

/**
 * 更新危险源
 */
export const updateDangerSourceApi = (data: UpdateDangerSourceCommand) => {
  return http.request<ResponseData<void>>("put", "/airport/danger-source", {
    data
  });
};
